package face.pay.web.cpn.CpnMchServiceInfo;


import face.pay.cpn.cpnmachServiceinfo.ICpnMchServiceInfoService;
import face.pay.entity.CpnMchServiceInfo;
import face.pay.entity.CpnMchWorkTime;
import face.pay.entity.UserInfo;
import face.pay.security.annotation.CurrentUser;
import face.pay.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("cpnService")
public class CpnMchServiceInfoController {


    @Autowired
    private ICpnMchServiceInfoService iCpnMchServiceInfoService;


    @RequestMapping("index")
    public String index(@CurrentUser UserInfo loginUser, Model model) {
        CpnMchServiceInfo cpnServiceInfo = this.iCpnMchServiceInfoService.querycpnServiceInfo(loginUser);
        List<CpnMchWorkTime> list = this.iCpnMchServiceInfoService.queryMchWorkTime(loginUser);
        model.addAttribute("workTimelist", list);
        model.addAttribute("cpnServiceInfo", cpnServiceInfo);
        return "cpn/CpnMachServiceInfo";
    }


    /**
     * 更新资料
     *
     * @param loginUser
     * @param cpnMchServiceInfo
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public ResultMessage editMchService(@CurrentUser UserInfo loginUser, CpnMchServiceInfo cpnMchServiceInfo) {
        return this.iCpnMchServiceInfoService.ediet(loginUser, cpnMchServiceInfo);
    }


    /**
     * 提交商家工作时间
     *
     * @param loginUser
     * @param workTimes
     * @return
     */
    @RequestMapping("/updataWorkTime")
    @ResponseBody
    public ResultMessage updataWorkTime(@CurrentUser UserInfo loginUser, @RequestBody List<CpnMchWorkTime> workTimes) {
        return this.iCpnMchServiceInfoService.updataWorkTime(loginUser, workTimes);
    }

}
